/// <reference path="../declare/dec.d.ts"/>
import {routeConfig} from "../route/route.ts"

interface Action {
    url: string
    post: (data: postDataItf | 　loginDataItf, callback: {
        success: (data) => void,
        error: (data) => void
    }) => void
}

interface postDataItf {
    province_id: number
    sessionid: string
    year?: number
    month?: number
}

interface loginDataItf {
    username: string
    password: string
}

export default function getAction(action: string): Action {
    return {
        url: `${routeConfig.domain + routeConfig.path}/${action}`,
        post(data, callback) {
            $.ajax({
                url: this.url,
                type: 'post',
                data,
                success: callback.success,
                error: callback.error
            })
        }
    }
}

interface ImportAction{
    url: string
    post: (data:FormData, callback: {
        success: (data) => void,
        error: (data) => void
    }) => void
}

export function getActionOfImportPhone(action: string):ImportAction {
    return {
        url: `${routeConfig.domain + routeConfig.path}/${action}`,
        post(data, callback) {
            $.ajax({
                url: this.url,
                type: 'post',
                processData: false,
                data,
                contentType: false,
                success: callback.success,
                error: callback.error
            })
        }
    }
}
